<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('养修服务单项列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="appointment-form">
                <div class="select-list">
                    <ul>
                        <li class="select-time">
                            <label>预约时间： </label>
                            <input type="text" class="time-input" placeholder="开始时间" name="params[beginTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" placeholder="结束时间" name="params[endTime]"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="business:appointment:add">
                <i class="fa fa-plus"></i> 新增
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    let prefix = ctx + "business/appointment";
    let statementStatusDatas = [[${@dict.getType('cmi_status')}]];
    let serviceTypeDatas = [[${@dict.getType('si_service_catalog')}]];

    function generateStatement(id) {
        let row = $("#bootstrap-table").bootstrapTable("getRowByUniqueId",id);
        var msg = "确认生成结算单吗?";
        if(row.status==4){
            msg = "是否需要查看对应的结算单明细";
        }
        $.modal.confirm(msg, function() {
            $.operate.post(prefix + "/generateStatement",{id:id},function(result){
                console.log(result);
                if(result.code==web_status.SUCCESS){
                    var url = ctx + "business/statementItem/itemDetail/" + result.data;
                    $.modal.openTab("结算单详情", url);
                }
            });
        });

    }

    function arrivalHandler(id) {
        $.modal.confirm("确认该客户抵达门店吗?",function () {
            $.operate.submit(prefix+"/gotoStatus/"+id,"post")
        })
    }
    function cancelHandler(id){
        $.modal.confirm("确认取消该客户预约吗?",function () {
            $.operate.submit(prefix+"/cancelStatus/"+id,"post")
        })
    }
    $(function () {
        var options = {
            url: prefix + "/query",   //查询的数据地址
            createUrl: prefix + "/addPage", //新增页面的地址
            updateUrl: prefix + "/editPage/{id}", //编辑页面的地址
            removeUrl: prefix + "/remove", //删除的地址
            modalName: "养修信息预约", //模态框的名称
            uniqueId:"id",//设置为唯一字段（主键字段)
            columns: [
                {
                    field: 'id',
                    title: '编号',
                    visible: false
                },
                {
                    field: 'customerName',
                    title: '客户名称',
                    sortable: true
                },
                {
                    field: 'customerPhone',
                    title: '客户联系方式',
                    sortable: true,
                },
                {
                    field: 'appointmentTime',
                    title: '预约时间',
                    sortable: true
                },
                {
                    field: 'actualArrivalTime',
                    title: '实际到店时间',
                    sortable: true
                },
                {
                    field: 'licensePlate',
                    title: '车牌号码',
                    sortable: true
                },
                {
                    field: 'carSeries',
                    title: '汽车类型',
                    sortable: true
                },
                {
                    field: 'serviceType',
                    title: '服务类型',
                    sortable: true,
                    formatter:function (value,row,index) {
                        return $.table.selectDictLabel(serviceTypeDatas,value);
                    }
                },
                {
                    field: 'info',
                    title: '备注信息',
                    sortable: true
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter:function (value, row, index) {
                        return $.table.selectDictLabel(statementStatusDatas,value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var editBtnFlag =row.status>0?"disabled":"";
                        var arrivalBtnFlag = row.status>0?"disabled":"";
                        var statementBtnFlag = (row.status!=1 && row.status!=4)?"disabled":"";
                        var cancelBtnFlag = row.status>0?"disabled":"";
                        var removeBtnFlag = row.status>0?"disabled":"";
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs '+editBtnFlag+'" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-warning btn-xs '+arrivalBtnFlag+'" href="javascript:void(0)" onclick="arrivalHandler(\'' + row.id + '\')"><i class="fa fa-sign-in"></i>到店</a> ');
                        actions.push('<a class="btn btn-primary btn-xs '+statementBtnFlag+'" href="javascript:void(0)" onclick="generateStatement(\'' + row.id + '\')"><i class="fa fa-shopping-cart"></i>结算单</a> ');
                        var more = [];
                        more.push("<a class='btn btn-default btn-xs "+cancelBtnFlag+"' href='javascript:void(0)' onclick='cancelHandler(" + row.id + ")'><i class='fa fa-reply'></i>取消</a> ");
                        more.push("<a class='btn btn-default btn-xs "+removeBtnFlag+"' href='javascript:void(0)' onclick='$.operate.remove(" + row.id + ")'><i class='fa fa-remove'></i>删除</a>");
                        actions.push('<a tabindex="0" class="btn btn-info btn-xs" role="button" data-container="body" data-placement="left" data-toggle="popover" data-html="true" data-trigger="hover" data-content="' + more.join('') + '"><i class="fa fa-chevron-circle-right"></i>更多操作</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);

    });
</script>
</body>
</html>